package com.lvmama.rhino.pojo.comment.Enum;

import org.apache.commons.lang3.StringUtils;

/**
 * 情感极性（0表示消极，1表示中性，2表示积极）
 */
public enum EnumForComment {

    all(-1, "全部"),
    positive(2, "好评"),
    neuter(1, "中评"),
    negative(0, "差评");

    private int value;
    private String showName;

    EnumForComment(int value, String showName) {
        this.value = value;
        this.showName = showName;
    }

    public int getValue() {
        return value;
    }

    public void setValue(int value) {
        this.value = value;
    }

    public String getShowName() {
        return showName;
    }

    public void setShowName(String showName) {
        this.showName = showName;
    }

    /**
     * 获取全部评论
     *
     * @return EnumForComment[]
     */
    public static EnumForComment[] getAllComment() {
        EnumForComment[] enumForComments = new EnumForComment[4];
        enumForComments[0] = EnumForComment.all;
        enumForComments[1] = EnumForComment.negative;
        enumForComments[2] = EnumForComment.neuter;
        enumForComments[3] = EnumForComment.positive;
        return enumForComments;
    }

    /**
     * 根据名称获取值
     *
     * @param name
     * @return
     */
    public static int getCommentValue(String name) {
        int value = -1;
        if (StringUtils.isEmpty(name)) {
            return value;
        }

        for (EnumForComment comment : EnumForComment.values()) {
            if (comment.getShowName().equals(name)) {
                value = comment.getValue();
                break;
            }
        }
        return value;
    }

    /**
     * 根据值获取名称
     *
     * @param value
     * @return
     */
    public static String getCommentShowname(int value) {
        String name = "";
        for (EnumForComment comment : EnumForComment.values()) {
            if (value == comment.getValue()) {
                name = comment.getShowName();
                break;
            }
        }
        return name;
    }

}
